﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TestAngular.Migrations
{
    public partial class ItemMaster_BillOfMaterials : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "BasicArchivesBillOfMaterials",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    Level = table.Column<int>(type: "int", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DisplayName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    Version = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    ItemMasterId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ItemCode = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    ItemName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    ItemSpec = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    UseCount = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    ParentCount = table.Column<decimal>(type: "decimal(18,6)", nullable: false),
                    UnitId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BillOfMaterialsId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Code = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    SourceType = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SourceKey = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BasicArchivesBillOfMaterials", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BasicArchivesBillOfMaterials_BasicArchivesAuxiliaryUnit_UnitId",
                        column: x => x.UnitId,
                        principalTable: "BasicArchivesAuxiliaryUnit",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesBillOfMaterials_BasicArchivesBillOfMaterials_BillOfMaterialsId",
                        column: x => x.BillOfMaterialsId,
                        principalTable: "BasicArchivesBillOfMaterials",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_BasicArchivesBillOfMaterials_BasicArchivesBillOfMaterials_ParentId",
                        column: x => x.ParentId,
                        principalTable: "BasicArchivesBillOfMaterials",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_BasicArchivesBillOfMaterials_BasicArchivesItemMaster_ItemMasterId",
                        column: x => x.ItemMasterId,
                        principalTable: "BasicArchivesItemMaster",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesBillOfMaterials_BillOfMaterialsId",
                table: "BasicArchivesBillOfMaterials",
                column: "BillOfMaterialsId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesBillOfMaterials_ItemMasterId",
                table: "BasicArchivesBillOfMaterials",
                column: "ItemMasterId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesBillOfMaterials_ParentId",
                table: "BasicArchivesBillOfMaterials",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_BasicArchivesBillOfMaterials_UnitId",
                table: "BasicArchivesBillOfMaterials",
                column: "UnitId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "BasicArchivesBillOfMaterials");
        }
    }
}
